﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using JiveMessenger.Models;
using JiveMessenger.ViewModels;
using JiveMessenger.Views;
using System;
using System.Windows;
using System.Windows.Documents;

namespace JiveMessenger.ViewModels
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class ViewModelWelcomeInfo : ViewModelTab
    {
        public RelayCommand<int> OpenOptionsCommand { get; set; }
        public RelayCommand OpenFontSelectorCommand { get; set; }
        public RelayCommand<Uri> OpenUriCommand { get; set; }


        private FlowDocument _document;
        public FlowDocument Document
        {
            get { return _document; }
            set
            {
                if (_document != value)
                {
                    Set(() => Document, ref _document, value);
                }
            }
        }

        

        /// <summary>
        /// Initializes a new instance of the ViewModelWelcomeTab class.
        /// </summary>
        public ViewModelWelcomeInfo()
        {
            ViewModelName = "Welcome";
            this.ID = "JiveWelcomeTab#"+Guid.NewGuid().ToString();
            this.Document = Application.LoadComponent(new Uri("/Resources/WelcomeDocument.xaml", UriKind.Relative)) as FlowDocument;

            this.OpenOptionsCommand= new RelayCommand<int>(OpenOptionsCommandAction);
            this.OpenFontSelectorCommand = new RelayCommand(OpenFontSelectorCommandAction);
            this.OpenUriCommand = new RelayCommand<Uri>(OpenUriCommandAction);
        }

        private void OpenUriCommandAction(Uri url)
        {
            Messenger.Default.Send(new NotificationMessage<Uri>(this, url, "OpenUrl"));
        }

        private void OpenFontSelectorCommandAction()
        {
            Messenger.Default.Send(new NotificationMessage(this, "ChangeFont"));
        }

        private void OpenOptionsCommandAction(int pageNum)
        {
            OptionsPage page = OptionsPage.Layout;
            try
            {
                 page= (OptionsPage)pageNum;
            }
            catch{}
            Messenger.Default.Send(new NotificationMessage(this, page, "OpenOptions"));
        }

        public override void Cleanup()
        {
            base.Cleanup();
        }

        public bool Equals(ViewModelTab other)
        {
            return this.ID == other.ID;
        }
    }
}